<?php

namespace App\Http\Controllers\Admin;

use App\Admin\Auth;
use App\Admin\Role;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use Input;

class RoleController extends Controller
{
    /**
     * 列表
     */
    public function index()
    {
        $data = Role::get();
        return view('admin.role.index',compact('data'));
    }
    /**
     * 分派权限
     */
    public function assign()
    {
        //判断请求类型
        if(Input::method() == 'POST'){
            $data = Input::only(['id','auth_id']);
            $role = new Role();
            return $role->assignAuth($data);
        }else{
            $top = Auth::where('pid','0')->get();
            $cat = Auth::where('pid','!=','0')->get();
            //获取当前角色具备的权限id集合
            $ids = Role::where('id',Input::get('id'))->value('auth_ids');
            return view('admin.role.assign',compact('top','cat','ids'));
        }

    }
}
